function bindElements(){

	//bind submit button
	$("#Submit").bind('click', function(){
		if(validateElements()){
			$("#frmStep5").submit();
		}
	});

}

var validateElements = function(){
	//sets error count to zero, if greater then zero, some data is not valid
	var error_count = 0;

	//var for required element error message.  A custom message can 
	//be set on the input element called error_message
	var require_message = function(id){		
		return $("#" + id).attr('error_message');	
	}
	
	//these fields are integer fields
	var integer_fields = $("input[id^='EmpNo']");
	
	//removes error messages from previous validation.
	$(".ui-state-error").removeClass();
	
	//creates html of errors
	var html_errors = function(){
		var error_link = "";		

		//if int field is entered or mal-formed, error is triggered
		$.map(integer_fields, function(field){
			if( $("#" + field.id).val() && isNaN( $("#" + field.id).val() ) ){
				error_count++;
				$("#" + field.id).addClass('ui-state-error');
				error_link = error_link + "<span class='link_error'" + "id='errorlink:" + field.id + "'>" + 
				field.id + ":</span> " + require_message(field.id) + "<br />";
			}
		});
		
		return error_link;
	};
	
	//creates jquery ui dialog box html
	$("div.entry").append('<div id="error_dialog" style="width: auto;"><p>' + html_errors() + '</p></div>');
	
	//creates jquery ui dialog box object
	var $error_dialog = $('#error_dialog').dialog({
		autoOpen: false, width: 'auto', modal: true, title: 'The following fields have errors', resizable: false,
		open: function(event, ui) { $("div.ui-dialog-titlebar").width( $(".ui-dialog").width() ); },
		close: function(event, ui) {$(this).dialog( "destroy" ) }
	});

	//if no errors in validation, well... the data is valid!
	if(error_count){
		$error_dialog.dialog('open');
		$("span[id^='errorlink:']").click(function(){
			var element_id = "#" + this.id.split(":")[1];
			$.scrollTo(element_id);//jquery pluging ScrollTo
			$error_dialog.dialog('close');
			$(element_id).focus();
		});
		return false;
	}else{return true;}
};



$(function(){
	bindElements();
});